/*
 * @Author: your name
 * @Date: 2021-12-21 17:32:09
 * @LastEditTime: 2021-12-22 18:37:28
 * @LastEditors: Please set LastEditors
 * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 * @FilePath: /project_am/am-server/app/controller/course.js
 */
const { Controller } = require('egg');
const Message = require('../utils/Message')

/**
* @Controller course-controller:课程相关接口
*/

class CourseController extends Controller {

    /**
   * @Router get /course/pageQuery
   * @summary 分页查询课程信息
   * @request query string *page
   * @request query string *pageSize
   * @apikey
  */
  async pageQuery () {
    // console.log('====');
    const { ctx, service } = this
    // 接受用户请求 
    // 获取用户参数 ctx.query 
    // 调用service查询
    const coursesVM = await service.course.pageQuery(ctx.query)
    ctx.body = Message.success(coursesVM)
  }

  /**
   * @Router post /course/saveOrUpdate
   * @summary 保存或修改课程信息
   * @request query number id
   * @request query string *course
   * @apikey
  */
    async saveOrUpdate () {
    const { ctx, service } = this
    // 接受用户请求 
    // 获取用户参数 ctx.query 
    // 调用service查询
    await service.course.saveOrUpdate(ctx.query)
    ctx.body = Message.success("操作成功")
    }


  /**
  * @Router delete /course/deleteById
  * @summary 根据id课程删除
  * @request query string *id 课程id
  * @apikey
 */
  async deleteById () {
    const { ctx, service } = this
    ctx.validate({
      id: 'string'
    }, ctx.query)
    await service.course.deleteById(ctx.query.id)

    ctx.body = Message.success('删除成功')
  }
}
module.exports = CourseController;